package cn.hinglo.gameclaw.admin.dao;

import cn.hinglo.gameclaw.admin.entity.UserAddData;
import cn.hinglo.gameclaw.admin.entity.UserData;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @createTime: 2018/1/26
 * @author: HingLo
 * @description: 首页管理的数据访问层
 */
@Repository
public interface AdminIndexDao {

    /**
     * 统计QQ与微信用户有多少人
     * QQ：type=3
     * 微信： type=2
     *
     * @return QQ与微信的人数对象
     */
    @Select("select (select count(id) from user where type=3 ) as qq,(select count(id) from user where type=2) as weixin ")
    UserData userProportionDao();

    /**
     * 过去num 天 人数变化
     *
     * @param num  过去的天数
     * @param type 账号类型
     * @return 结果集
     */
    @Select("select  date ,count(id) as num from user where type=#{type} and to_days(now())-to_days(date)<=#{num} group by date order by date desc")
    List<UserAddData> userAddDataDao(@Param("num") Integer num, @Param("type") Integer type);

}
